package com.cskaoyan.bean.goods;

import com.cskaoyan.bean.baseresultVO.BaseParam;
import com.cskaoyan.bean.domain.Comment;
import com.cskaoyan.bean.domain.Goods;
import com.github.pagehelper.PageInfo;
import lombok.Data;

import java.util.List;

/**
 * @BelongProject: java35th-market
 * @BelongPackage: com.cskaoyan.bean
 * @Author: zijin
 * @Createtime: 2021-11-27 星期六 16:35
 * @Description: todo
 */
@Data
public class BasePageData<T> {

    private Integer limit;

    private Integer page;

    private Integer pages;

    private Integer total;

    private List<T> list;

    public static BasePageData ok(List<Goods> users, BaseParam pageParams) {

        PageInfo goodsInfo = new PageInfo<>(users);
        BasePageData<Goods> goodsBasePageData = new BasePageData<>();
        goodsBasePageData.setPage(goodsInfo.getPageNum());
        goodsBasePageData.setLimit(goodsInfo.getPageSize());
        goodsBasePageData.setPages(goodsInfo.getPages());
        goodsBasePageData.setTotal((int) goodsInfo.getTotal());
        goodsBasePageData.setList(users);
        return goodsBasePageData;
    }

    public static BasePageData commentOk(List<Comment> comments, BaseParam pageParams) {

        PageInfo commentsInfo = new PageInfo<>(comments);
        BasePageData<Comment> commentBasePageData = new BasePageData<>();
        commentBasePageData.setPage(commentsInfo.getPageNum());
        commentBasePageData.setLimit(commentsInfo.getPageSize());
        commentBasePageData.setPages(commentsInfo.getPages());
        commentBasePageData.setTotal((int) commentsInfo.getTotal());
        commentBasePageData.setList(comments);
        return commentBasePageData;
    }
}
